<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/static/lib/layui-v2.6.3/css/layui.css}" media="all">
    <script type="text/javascript" th:src="@{/static/lib/layui-v2.6.3/layui.js}"></script>
    <script type="text/javascript" th:src="@{/static/lib/jquery-3.4.1/jquery-3.4.1.min.js}"></script>
    <script type="text/javascript" th:src="@{/static/js/jquery-1.9.1.min.js}"></script>
</head>
<body>
<form id="form2" action="" method="" class="layui-form">
    <input type="hidden" name="id" th:value="${list.id}">
    <div class="layui-form-item" style="width: 300px;display:inline-block;">
        <label class="layui-form-label">用户名:</label>
        <div class="layui-input-block">
            <input type="text" name="username" class="layui-input" th:value="${list.username}">
        </div>
    </div>
    <div class="layui-form-item" style="width: 300px;display:inline-block;">
        <label class="layui-form-label">密码:</label>
        <div class="layui-input-block">
            <input type="password" name="password" th:value="${list.password}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" style="width: 300px;display:inline-block;">
        <label class="layui-form-label">权限:</label>
        <div class="layui-input-block">
            <select name="grade" lay-verify="required">
                <option value="">[[${list.grade}]]</option>
                <option value="超级管理员">超级管理员</option>
                <option value="管理员">管理员</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item" style="width: 300px;display:inline-block;">
        <label class="layui-form-label">状态:</label>
        <div class="layui-input-block">
            <select name="state" lay-verify="required">
                <option value="">[[${list.state}]]</option>
                <option value="启用">启用</option>
                <option value="禁用">禁用</option>
            </select>
        </div>
    </div>
</form>
<div style="text-align:center">
    <button id="update" class="layui-btn">确定更改</button>
</div>
</body>
<script>
		layui.use(['layer', 'jquery', 'form'], function() {
			var layer = layui.layer;
			var $ = layui.jquery;
			var form = layui.form;
			form.render('select'); //表单渲染，得渲染才会有效果显示出来
			$(document).on('click', '#update', function() {
				var params = $("#form2").serialize();
				$.ajax({
					url: "/admin/update",
					type: "post",
					data: params,
					//请求发送完之后的回调函数
					success: function(info) {
						if (info == 1) {
							alert("修改成功！");
						} else {
							alert("修改失败！");
						}
						var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
						//刷新父类页面
						window.parent.location.reload();



					}
				})

			})
		})
	</script>
</html>
